﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraCharts;
using DevExpress.XtraEditors;
using Zero.POCO.Views;

namespace DevExpress.MailClient.Win.Controls.ProfilPenetration.Maximized
{
    public partial class WidgetVilleMaximized : DevExpress.XtraEditors.XtraUserControl
    {
        public WidgetVilleMaximized()
        {
            InitializeComponent();
        }

        public void UpdateStat(ProfilPenetrationView profilPenetrationView)
        {
            ccSupport.Series.Clear();
            var series1 = new Series(profilPenetrationView.ProfilPrincipale.ProfilPrincipale.SupportView.Nom, ViewType.Bar);

            series1.Points.Add(new SeriesPoint("Alger", profilPenetrationView.ProfilPrincipale.ProfilPrincipale.StatistiqueVille.Alger * 100 / profilPenetrationView.ProfilPrincipale.Vague.NombreAlger));
            series1.Points.Add(new SeriesPoint("Oran", profilPenetrationView.ProfilPrincipale.ProfilPrincipale.StatistiqueVille.Oran * 100 / profilPenetrationView.ProfilPrincipale.Vague.NombreOran));
            series1.Points.Add(new SeriesPoint("Setif", profilPenetrationView.ProfilPrincipale.ProfilPrincipale.StatistiqueVille.Setif * 100 / profilPenetrationView.ProfilPrincipale.Vague.NombreSetif));
            series1.Points.Add(new SeriesPoint("Constantine", profilPenetrationView.ProfilPrincipale.ProfilPrincipale.StatistiqueVille.Constantine * 100 / profilPenetrationView.ProfilPrincipale.Vague.NombreConstantine));
            series1.SeriesPointsSorting = SortingMode.Descending;
            ccSupport.Series.Add(series1);


            foreach (var profilPenetrationSup in profilPenetrationView.ProfilPrincipale.ProfilSupport)
            {
                var series2 = new Series(profilPenetrationSup.SupportView.Nom, ViewType.Bar);

                series2.Points.Add(new SeriesPoint("Alger", profilPenetrationSup.StatistiqueVille.Alger * 100 / profilPenetrationView.ProfilPrincipale.Vague.NombreAlger));
                series2.Points.Add(new SeriesPoint("Oran", profilPenetrationSup.StatistiqueVille.Oran * 100 / profilPenetrationView.ProfilPrincipale.Vague.NombreOran));
                series2.Points.Add(new SeriesPoint("Setif", profilPenetrationSup.StatistiqueVille.Setif * 100 / profilPenetrationView.ProfilPrincipale.Vague.NombreSetif));
                series2.Points.Add(new SeriesPoint("Constantine", profilPenetrationSup.StatistiqueVille.Constantine * 100 / profilPenetrationView.ProfilPrincipale.Vague.NombreConstantine));
                series2.SeriesPointsSorting = SortingMode.Descending;
                ccSupport.Series.Add(series2);    
            }

            // Format the the series labels.
            series1.Label.TextPattern = "{A}: {VP:p0}";

            List<int> listVague = profilPenetrationView.ProfilSupport.Select(e => e.Vague.Mois).ToList();
            listVague.Sort();



            ccVagueSupport.Series.Clear();
            var series_1 = new Series("Alger", ViewType.Line);

          

            for (int i = 0; i < listVague.Count; i++)
            {
                var profilPenetrationSup = profilPenetrationView.ProfilSupport.First(e => e.Vague.Mois == listVague[i]);
                series_1.Points.Add(new SeriesPoint(profilPenetrationSup.Vague.Libelle, profilPenetrationSup.ProfilPrincipale.StatistiqueVille.Alger * 100 / profilPenetrationSup.Vague.NombreAlger));
            }
            series_1.Points.Add(new SeriesPoint(profilPenetrationView.ProfilPrincipale.Vague.Libelle, profilPenetrationView.ProfilPrincipale.ProfilPrincipale.StatistiqueVille.Alger));

            ccVagueSupport.Series.Add(series_1);










             var series_2 = new Series("Oran", ViewType.Line);



            for (int i = 0; i < listVague.Count; i++)
            {
                var profilPenetrationSup = profilPenetrationView.ProfilSupport.First(e => e.Vague.Mois == listVague[i]);
                series_2.Points.Add(new SeriesPoint(profilPenetrationSup.Vague.Libelle, profilPenetrationSup.ProfilPrincipale.StatistiqueVille.Oran * 100 / profilPenetrationSup.Vague.NombreOran));
            }
            series_2.Points.Add(new SeriesPoint(profilPenetrationView.ProfilPrincipale.Vague.Libelle, profilPenetrationView.ProfilPrincipale.ProfilPrincipale.StatistiqueVille.Oran));

            ccVagueSupport.Series.Add(series_2);










            var series_3 = new Series("Constantine", ViewType.Line);



            for (int i = 0; i < listVague.Count; i++)
            {
                var profilPenetrationSup = profilPenetrationView.ProfilSupport.First(e => e.Vague.Mois == listVague[i]);
                series_3.Points.Add(new SeriesPoint(profilPenetrationSup.Vague.Libelle, profilPenetrationSup.ProfilPrincipale.StatistiqueVille.Constantine * 100 / profilPenetrationSup.Vague.NombreConstantine));
            }
            series_3.Points.Add(new SeriesPoint(profilPenetrationView.ProfilPrincipale.Vague.Libelle, profilPenetrationView.ProfilPrincipale.ProfilPrincipale.StatistiqueVille.Constantine));

            ccVagueSupport.Series.Add(series_3);












            var series_4 = new Series("Setif", ViewType.Line);



            for (int i = 0; i < listVague.Count; i++)
            {
                var profilPenetrationSup = profilPenetrationView.ProfilSupport.First(e => e.Vague.Mois == listVague[i]);
                series_4.Points.Add(new SeriesPoint(profilPenetrationSup.Vague.Libelle, profilPenetrationSup.ProfilPrincipale.StatistiqueVille.Setif));
            }
            series_4.Points.Add(new SeriesPoint(profilPenetrationView.ProfilPrincipale.Vague.Libelle, profilPenetrationView.ProfilPrincipale.ProfilPrincipale.StatistiqueVille.Setif * 100 / profilPenetrationView.ProfilPrincipale.Vague.NombreSetif));

            ccVagueSupport.Series.Add(series_4);

        }
    }
}
